#-------------------------------------------------------------------------------
# Name:        db_model
# Purpose:     for database
#
# Author:      irolary
#
# Created:     21-08-2010
# Copyright:   (c) irolary 2010
# Licence:     <your licence>
#-------------------------------------------------------------------------------
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from google.appengine.ext import db

class KonoDB(db.Model):
    email = db.StringProperty()
    name = db.StringProperty()
    lang = db.StringProperty()
    stlist = db.StringListProperty()
    date = db.DateTimeProperty(auto_now_add=True)
class KonoCount(db.Model):
    count = db.IntegerProperty()
class KonoError(db.Model):
    msg = db.StringProperty()


class DBservice(db.Model):
    def __init__(self, add=''):
        self._add=add
        self._results=None
    def getQuery(self):
        '''
        Return the query result
        '''
        return db.GqlQuery('SELECT * FROM '+'KonoDB')

    def isUser(self):
        command="SELECT * FROM "+ 'KonoDB' +" WHERE email = '"+self._add+"'"
        q = db.GqlQuery(command)
        num = q.count()
        while num >1:
            db.delete(q)
        if num==1:
            self.results=q
        elif num==0:
            return False

    def setName(self,name):
        name=name
        db.put()
    def setStlist(self,stlist):
        stlist=stlist
        db.put()
    def setLang(self,lang):
        lang=lang
        db.put()
    def createUser(self):
        newEntity=KonoDB()
        newEntity.email=self._add.lower()
        db.put(newEntity)
    def delUser(self):
        delete()
    def dauftUser(self):
        pass

if __name__ == '__main__':
    main()